package org.example.controller;

import org.example.dto.DailyUserResponseDTO;
import org.example.dto.UserVO;
import org.example.entity.Users;
import org.example.dto.UserStatisticsDTO;
import org.example.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author ljh
 * @version 1.0
 * @Description
 * @date 2025/7/21 15:00
 */
@RestController
@CrossOrigin(origins = "*")
public class UserController {
    @Autowired
    private UsersService usersService;

    @GetMapping("/list")
    public List<Users> getListData(){
        return usersService.getAllUsers();
    }
    @GetMapping("/update")
    public String updateUserInfo(Users users){
        return usersService.updateUserInfo(users);
    }

    @GetMapping("/statistics")
    public ResponseEntity<UserStatisticsDTO> getUserStatistics() {
        UserStatisticsDTO statistics = usersService.getUserStatistics();
        return ResponseEntity.ok(statistics);
    }

    @GetMapping("/daily-list")
    public ResponseEntity<List<UserVO>> getDailyUserList(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        List<UserVO> users = usersService.getDailyActiveUsers(date);
        return ResponseEntity.ok(users);
    }
    @GetMapping("/daily-count")
    public ResponseEntity<Map<String, Integer>> getDailyUserCount(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) {
        int count = usersService.getDailyActiveUserCount(date);
        return ResponseEntity.ok(Collections.singletonMap("count", count));
    }

}
